
//Table A4 final run
log using "$rootpath/log/Table_A4_Results.log", replace
eststo clear
use "$rootpath/processed_data/Estimation_Data.dta", clear

//facility-level se
reghdfe  tot_damage treatXpost if key_estimation_sample==1, absorb(facility_id n5#year) vce(cluster facility_id)
estimates store res_level_damage1

//state-level se 
//reghdfe  tot_damage treatXpost if key_estimation_sample==1, absorb(facility_id n5#year) vce(cluster state_number)
//estimates store res_level_damage1state

//facility-level se
reghdfe  tot_damage treatXpost if key_estimation_sample==1&tot_damage<1e8, absorb(facility_id n5#year) vce(cluster facility_id)
estimates store res_level_damage2

//state-level se
//reghdfe  tot_damage treatXpost if key_estimation_sample==1tot_damage<1e8, absorb(facility_id n5#year) vce(cluster state_number)
//estimates store res_level_damage2state

gen log_damX=log(tot_damage+1)
//facility-level se
reghdfe  log_damX treatXpost if key_estimation_sample==1, absorb(facility_id n5#year) vce(cluster facility_id)
estimates store res_log_damage1

//state-level se
//reghdfe  log_damX treatXpost if key_estimation_sample==1, absorb(facility_id n5#year) vce(cluster state_number)
//estimates store res_log_damage1state

///This is emissions

//facility-level se
reghdfe  tot_emissions treatXpost if key_estimation_sample==1, absorb(facility_id n5#year) vce(cluster facility_id)
estimates store res_level_emission1

//state-level se
//reghdfe  tot_emissions treatXpost if key_estimation_sample==1, absorb(facility_id n5#year) vce(cluster state_number)
//estimates store res_level_emission1state

//facility-level se
reghdfe  tot_emissions treatXpost if key_estimation_sample==1&tot_damage<1e8, absorb(facility_id n5#year) vce(cluster facility_id)
estimates store res_level_emission2

//state-level se
//reghdfe  tot_emissions treatXpost if key_estimation_sample==1&tot_damage<1e8, absorb(facility_id n5#year) vce(cluster state_number)
//estimates store res_level_emission2state


gen log_emisX=log(tot_emissions+1)
//facility-level se
reghdfe  log_emisX treatXpost if key_estimation_sample==1, absorb(facility_id n5#year) vce(cluster facility_id)
estimates store res_log_emission1

//state-level se
//reghdfe  log_emisX treatXpost if key_estimation_sample==1, absorb(facility_id n5#year) vce(cluster state_number)
//estimates store res_log_emission1state

esttab res_level_damage1  res_level_damage2 res_log_damage1  res_level_emission1 res_level_emission2 res_log_emission1 using "$rootpath/table_graph/TBL_A4.tex",  star( * 0.1 ** 0.05 *** 0.01) cells(b(star fmt(3)) se(par fmt(3))) keep(treatXpost _cons) scalars(N F) ar2 replace 

log close
